﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class MemDrawMoney
    {
        private readonly Chain.IDAL.MemDrawMoney dal = new Chain.IDAL.MemDrawMoney();

        public int Add(Chain.Model.MemDrawMoney model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.MemDrawMoney> DataTableToList(DataTable dt)
        {
            List<Chain.Model.MemDrawMoney> list = new List<Chain.Model.MemDrawMoney>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.MemDrawMoney item = new Chain.Model.MemDrawMoney();
                    if ((dt.Rows[i]["DrawMoneyID"] != null) && (dt.Rows[i]["DrawMoneyID"].ToString() != ""))
                    {
                        item.DrawMoneyID = int.Parse(dt.Rows[i]["DrawMoneyID"].ToString());
                    }
                    if ((dt.Rows[i]["DrawMoneyMemID"] != null) && (dt.Rows[i]["DrawMoneyMemID"].ToString() != ""))
                    {
                        item.DrawMoneyMemID = int.Parse(dt.Rows[i]["DrawMoneyMemID"].ToString());
                    }
                    if ((dt.Rows[i]["DrawMoneyAccount"] != null) && (dt.Rows[i]["DrawMoneyAccount"].ToString() != ""))
                    {
                        item.DrawMoneyAccount = dt.Rows[i]["DrawMoneyAccount"].ToString();
                    }
                    if ((dt.Rows[i]["DrawMoney"] != null) && (dt.Rows[i]["DrawMoney"].ToString() != ""))
                    {
                        item.DrawMoney = decimal.Parse(dt.Rows[i]["DrawMoney"].ToString());
                    }
                    if ((dt.Rows[i]["DrawActualMoney"] != null) && (dt.Rows[i]["DrawActualMoney"].ToString() != ""))
                    {
                        item.DrawActualMoney = decimal.Parse(dt.Rows[i]["DrawActualMoney"].ToString());
                    }
                    if ((dt.Rows[i]["DrawMoneyRemark"] != null) && (dt.Rows[i]["DrawMoneyRemark"].ToString() != ""))
                    {
                        item.DrawMoneyRemark = dt.Rows[i]["DrawMoneyRemark"].ToString();
                    }
                    if ((dt.Rows[i]["DrawMoneyShopID"] != null) && (dt.Rows[i]["DrawMoneyShopID"].ToString() != ""))
                    {
                        item.DrawMoneyShopID = int.Parse(dt.Rows[i]["DrawMoneyShopID"].ToString());
                    }
                    if ((dt.Rows[i]["DrawMoneyUserID"] != null) && (dt.Rows[i]["DrawMoneyUserID"].ToString() != ""))
                    {
                        item.DrawMoneyUserID = int.Parse(dt.Rows[i]["DrawMoneyUserID"].ToString());
                    }
                    if ((dt.Rows[i]["DrawMoneyCreateTime"] != null) && (dt.Rows[i]["DrawMoneyCreateTime"].ToString() != ""))
                    {
                        item.DrawMoneyCreateTime = DateTime.Parse(dt.Rows[i]["DrawMoneyCreateTime"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int DrawMoneyID)
        {
            return this.dal.Delete(DrawMoneyID);
        }

        public bool DeleteList(string DrawMoneyIDlist)
        {
            return this.dal.DeleteList(DrawMoneyIDlist);
        }

        public bool Exists(int DrawMoneyID)
        {
            return this.dal.Exists(DrawMoneyID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetDataByTime(DateTime starttime, DateTime endtime, string strwhere)
        {
            return this.dal.GetDataByTime(starttime, endtime, strwhere);
        }

        public decimal GetDrawMoney(string strWhere)
        {
            return this.dal.GetDrawMoney(strWhere);
        }

        public DataSet GetDrawMoneyCount(string strSql)
        {
            return this.dal.GetDrawMoneyCount(strSql);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.MemDrawMoney GetModel(int DrawMoneyID)
        {
            return this.dal.GetModel(DrawMoneyID);
        }

        public List<Chain.Model.MemDrawMoney> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.MemDrawMoney model)
        {
            return this.dal.Update(model);
        }
    }
}

